package com.google.code.coma.loadbalancer;

import com.google.code.coma.Coma;
import com.google.code.coma.loadbalancer.rmi.RmiLoadBalancer;
import com.google.code.coma.loadbalancer.space.SpaceLoadBalancer;

import java.util.Arrays;

/**
 * @author Dominik Strasser, dominikstr@gmail.com
 */
public class LoadBalancerLauncher {
	public static void main(String... args) {
		Runnable r = null;

		if (args[0].equals("SPACE")) {
			r = new SpaceLoadBalancer("xvsm://localhost:4242", Arrays.copyOfRange(args, 1, args.length));
		} else if (args[0].equals("RMI")) {
			r = new RmiLoadBalancer(Arrays.copyOfRange(args, 1, args.length));
		}

		if (r == null) {
			System.err.println("Invalid implementation args");
			return;
		}

		while (true) {
			System.out.println("===================================================");
			System.out.println("  RUN");
			System.out.println("===================================================");
			try {
				r.run();
			} catch (Exception e) {
				System.out.println("Reschedule load balancer");
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
